+2007-06-06 Yevgen Muntyan <muntyan@tamu.edu>
+
+ * gtk/gtkwidget.c:
+ * gtk/gtkwidget.h: new method, gtk_widget_modify_cursor() (#89314).
+
+ * gtkrc.c:
+ * gtkrc.h: new functions _gtk_rc_style_set_rc_property() and
+ _gtk_rc_style_unset_rc_property().
+
+ * gtk/gtk.symbols: added gtk_widget_modify_cursor.
+
+ * tests/testtext.c (do_cursor_visible_changed):
+ * tests/testgtk.c (create_styles): test it.
+
2007-06-06 Richard Hult <richard@imendio.com>
* gdk/quartz/gdkevents-quartz.c (find_mouse_window_for_ns_event)
gtk_widget_modify_base
gtk_widget_modify_bg
gtk_widget_modify_fg
+gtk_widget_modify_cursor
gtk_widget_modify_font
gtk_widget_modify_style
gtk_widget_modify_text
gconstpointer bsearch_node2);
static void gtk_rc_set_free (GtkRcSet *rc_set);
+static void insert_rc_property (GtkRcStyle *style,
+ GtkRcProperty *property,
+ gboolean replace);
+
static const GScannerConfig gtk_rc_scanner_config =
{
return style;
}
+void
+_gtk_rc_style_set_rc_property (GtkRcStyle *rc_style,
+ GtkRcProperty *property)
+{
+ g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
+ g_return_if_fail (property != NULL);
+
+ insert_rc_property (rc_style, property, TRUE);
+}
+
+void
+_gtk_rc_style_unset_rc_property (GtkRcStyle *rc_style,
+ GQuark type_name,
+ GQuark property_name)
+{
+ GtkRcProperty *node;
+
+ g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
+
+ node = _gtk_rc_style_lookup_rc_property (rc_style, type_name, property_name);
+
+ if (node != NULL)
+ {
+ guint index = node - (GtkRcProperty *) rc_style->rc_properties->data;
+ g_value_unset (&node->value);
+ g_free (node->origin);
+ g_array_remove_index (rc_style->rc_properties, index);
+ }
+}
+
void
gtk_rc_style_ref (GtkRcStyle *rc_style)
{
const GtkRcProperty* _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
GQuark type_name,
GQuark property_name);
+void _gtk_rc_style_set_rc_property (GtkRcStyle *rc_style,
+ GtkRcProperty *property);
+void _gtk_rc_style_unset_rc_property (GtkRcStyle *rc_style,
+ GQuark type_name,
+ GQuark property_name);
GSList * _gtk_rc_style_get_color_hashes (GtkRcStyle *rc_style);
gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
}
+static void
+modify_color_property (GtkWidget *widget,
+ GtkRcStyle *rc_style,
+ const char *name,
+ const GdkColor *color)
+{
+ GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
+ GQuark property_name = g_quark_from_string (name);
+
+ if (color)
+ {
+ GtkRcProperty rc_property = {0};
+ char *color_name;
+
+ rc_property.type_name = type_name;
+ rc_property.property_name = property_name;
+ rc_property.origin = NULL;
+
+ color_name = gdk_color_to_string (color);
+ g_value_init (&rc_property.value, G_TYPE_STRING);
+ g_value_take_string (&rc_property.value, color_name);
+
+ _gtk_rc_style_set_rc_property (rc_style, &rc_property);
+
+ g_value_unset (&rc_property.value);
+ }
+ else
+ _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
+}
+
+/**
+ * gtk_widget_modify_cursor:
+ * @widget: a #GtkWidget
+ * @primary: the color to use for primary cursor (does not need to be
+ * allocated), or %NULL to undo the effect of previous calls to
+ * of gtk_widget_modify_cursor().
+ * @secondary: the color to use for secondary cursor (does not need to be
+ * allocated), or %NULL to undo the effect of previous calls to
+ * of gtk_widget_modify_cursor().
+ *
+ * Sets the font to use for a widget. All other style values are left
+ * untouched. See also gtk_widget_modify_style().
+ *
+ * Since: 2.12
+ **/
+void
+gtk_widget_modify_cursor (GtkWidget *widget,
+ const GdkColor *primary,
+ const GdkColor *secondary)
+{
+ GtkRcStyle *rc_style;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ rc_style = gtk_widget_get_modifier_style (widget);
+
+ modify_color_property (widget, rc_style, "cursor-color", primary);
+ modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
+
+ gtk_widget_modify_style (widget, rc_style);
+}
+
/**
* gtk_widget_modify_font:
* @widget: a #GtkWidget
void gtk_widget_modify_base (GtkWidget *widget,
GtkStateType state,
const GdkColor *color);
+void gtk_widget_modify_cursor (GtkWidget *widget,
+ const GdkColor *primary,
+ const GdkColor *secondary);
void gtk_widget_modify_font (GtkWidget *widget,
PangoFontDescription *font_desc);
gtk_widget_modify_base (entry, GTK_STATE_NORMAL, &yellow);
gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
+ label = gtk_label_new ("Cursor:");
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+ entry = gtk_entry_new ();
+ gtk_entry_set_text (GTK_ENTRY (entry), "Some Text");
+ gtk_widget_modify_cursor (entry, &red, &red);
+ gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
+
label = gtk_label_new ("Multiple:");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
gtk_text_view_set_editable (GTK_TEXT_VIEW (view->text_view), callback_action);
}
+static void
+change_cursor_color (GtkWidget *widget,
+ gboolean set)
+{
+ if (set)
+ {
+ GdkColor red = {0, 65535, 0, 0};
+ gtk_widget_modify_cursor (widget, &red, &red);
+ }
+ else
+ gtk_widget_modify_cursor (widget, NULL, NULL);
+}
+
static void
do_cursor_visible_changed (gpointer callback_data,
guint callback_action,
{
View *view = view_from_widget (widget);
- gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view->text_view), callback_action);
+ switch (callback_action)
+ {
+ case 0:
+ gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view->text_view), FALSE);
+ break;
+ case 1:
+ gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view->text_view), TRUE);
+ change_cursor_color (view->text_view, FALSE);
+ break;
+ case 2:
+ gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view->text_view), TRUE);
+ change_cursor_color (view->text_view, TRUE);
+ break;
+ }
}
static void
{ "/Settings/Not editable", NULL, do_editable_changed, FALSE, "/Settings/Editable" },
{ "/Settings/sep1", NULL, NULL, 0, "<Separator>" },
- { "/Settings/Cursor visible", NULL, do_cursor_visible_changed, TRUE, "<RadioItem>" },
- { "/Settings/Cursor not visible", NULL, do_cursor_visible_changed, FALSE, "/Settings/Cursor visible" },
+ { "/Settings/Cursor normal", NULL, do_cursor_visible_changed, 1, "<RadioItem>" },
+ { "/Settings/Cursor not visible", NULL, do_cursor_visible_changed, 0, "/Settings/Cursor normal" },
+ { "/Settings/Cursor colored", NULL, do_cursor_visible_changed, 2, "/Settings/Cursor normal" },
{ "/Settings/sep1", NULL, NULL, 0, "<Separator>" },
{ "/Settings/Left-to-Right", NULL, do_direction_changed, GTK_TEXT_DIR_LTR, "<RadioItem>" },